package stream;

import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Demo1 {

    private boolean flag;

    private int value;

    public boolean getFlag() {
        return flag;
    }

    public int getValue() {
        return value;
    }

    public static void main(String[] args) {
        List<Apple> apples = Arrays.asList(
                new Apple("1", 90),
                new Apple("2", 100),
                new Apple("3", 110),
                new Apple("4", 120),
                new Apple("5", 130)
        );
//        apples.stream().filter(a -> {
//            System.out.println(a.getWight());
//            return a.getWight() > 90;}).skip(1).filter(a -> {
//            System.out.println("---------------------");
//            System.out.println(a.getWight());
//            return a.getWight() > 110;
//        }).map(a -> {
//            System.out.println(a.getColor());
//            return a.getColor();
//        }).limit(2).collect(Collectors.toList());
        System.out.println(apples.stream().map(Apple::getWight).collect(Collectors.maxBy(Integer::compare)));
//        apples.stream().collect(Collectors.maxBy(Apple :: compareWight));
//        System.out.println(apples.stream().map(Apple :: getWight).collect(Collectors.toList()).stream().reduce(0,(a,b) -> a+b));
//        System.out.println(apples.stream().map(Apple::getWight).reduce(0,(a,b) -> a+b));
//        System.out.println(apples.stream().allMatch(apple -> {return apple.getWight() > 10;}));
    }

    @Test
    public void homeWork() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        System.out.println(list.stream().map(i -> {
            return i * i;
        }).collect(Collectors.toList()));
    }

}
